package itbour.onetouchshow.fragment.home_v1_3;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.andview.adapter.BaseRecyclerHolder;
import com.google.gson.Gson;
import com.lsjr.utils.NetUtils;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshFooter;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.RefreshState;
import com.scwang.smartrefresh.layout.listener.OnMultiPurposeListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.umeng.analytics.MobclickAgent;
import com.youth.banner.Banner;
import com.youth.banner.listener.OnBannerListener;
import com.ys.uilibrary.utils.DisplayUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.Unbinder;
import itbour.onetouchshow.R;
import itbour.onetouchshow.activity.challengezone.video.ChooseVideoSizeActivity;
import itbour.onetouchshow.activity.search.SearchActivity;
import itbour.onetouchshow.activity.version1_3.ClassifyListActivity;
import itbour.onetouchshow.activity.version1_3.MainActivityV3;
import itbour.onetouchshow.activity.web.AdWebActivity;
import itbour.onetouchshow.activity.web.CommWebActivity;
import itbour.onetouchshow.adapter.HomeClassifyAdapter;
import itbour.onetouchshow.base.BaseApplication;
import itbour.onetouchshow.base.BaseRefreshAdapter;
import itbour.onetouchshow.base.mvp.MVPBaseFragment;
import itbour.onetouchshow.bean.AppBanner;
import itbour.onetouchshow.bean.ChallengeActionBean;
import itbour.onetouchshow.bean.DesignListBean;
import itbour.onetouchshow.bean.HomeClassifyBean;
import itbour.onetouchshow.bean.HomeDetailslBean;
import itbour.onetouchshow.bean.SpecialTopicBean;
import itbour.onetouchshow.bean.V_1_3HomePageDataBean;
import itbour.onetouchshow.constants.AppConst;
import itbour.onetouchshow.listener.MyRyItemListener;
import itbour.onetouchshow.observable.NetWorkObservable;
import itbour.onetouchshow.utils.ImageLoader;
import itbour.onetouchshow.utils.JumpUtils;
import itbour.onetouchshow.utils.SpUtils;
import itbour.onetouchshow.utils.T_;
import itbour.onetouchshow.utils.UIUtils;
import itbour.onetouchshow.utils.glide.GlideImageLoader;
import itbour.onetouchshow.utils.sharedpreference.PreferencesHelper;
import itbour.onetouchshow.utils.video.StatusBarUtils;
import itbour.onetouchshow.widget.GoToMovieFooterView;
import itbour.onetouchshow.widget.NoScrollGridView;
import itbour.onetouchshow.widget.gallery.CycleGalleryViewPager;

/**
 * Created by guoh on 2018/2/27.
 * 首页信息
 */

public class V_1_3HomeFragment extends MVPBaseFragment<V_1_3HomeContract.View, V_1_3HomePresenter> implements V_1_3HomeContract.View, NetWorkObservable.NetWorkObserver {


    private static final int FAST_CLICK_DELAY_TIME = 2000;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;
    @BindView(R.id.v_status_bar)
    View vStatusBar;
    @BindView(R.id.tv_homepage_hotsearch)
    TextView tvHomepageHotsearch;
    @BindView(R.id.id_ig_chall)
    ImageView idIgChall;
    @BindView(R.id.rl_circular_shape)
    RelativeLayout rlCircularShape;
    @BindView(R.id.rl_search_no_back)
    RelativeLayout rlSearchNoBack;
    @BindView(R.id.iv_personal_create)
    ImageView ivPersonalCreate;
    @BindView(R.id.ll_search_layout_container)
    LinearLayout llSearchLayoutContainer;
    Unbinder unbinder;
    private BaseRefreshAdapter baseRefreshAdapter;
    //8个分类适配器
    private HomeClassifyAdapter classifyAdapter;
    private Banner vBanner;
    private View headView;
    //防止快速点击
    private long lastClickTime = 0L;
    //旧的广告数据
    private List<String> oldBannerImages = new ArrayList<>();

    private RecyclerView.LayoutManager layoutManager;


    //搜索框的高度
    private int searchLayoutHeight;

    private V_1_3HomePresenter mPresenter = new V_1_3HomePresenter(this);
    private MyRyItemListener itemListener = new MyRyItemListener() {
        @Override
        public void onItemSelect(Object o) {
            if (System.currentTimeMillis() - lastClickTime < FAST_CLICK_DELAY_TIME) {
                return;
            }
            lastClickTime = System.currentTimeMillis();
            DesignListBean.ListBean data = (DesignListBean.ListBean) o;
            if (data == null) return;
            JumpUtils.goToVideoPlayer(getActivity(), data.getId());
        }
    };

    @Override
    protected int getLayoutId() {
        return R.layout.base_refresh_fragment_v_1_3;
    }

    @Override
    protected void afterCreate(Bundle savedInstanceState) {
        initStatusBar(vStatusBar);
        BaseApplication.instance().registerNetWorkObserver(this);
        baseRefreshAdapter = new HomepageItemAdapter(getContext(), null);
        headView = UIUtils.inflate(R.layout.view_1_3_home_header);
        llSearchLayoutContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                gotoSearch();
            }
        });
        ivPersonalCreate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //自由创建入口
                if (PreferencesHelper.getData(AppConst.KEY_PERSONAL_CREATE_CONFIG) == null) {
                    mPresenter.getFreedomCreateConfigInfo();
                } else {
                    openActivity(ChooseVideoSizeActivity.class);
                }
            }
        });
        initRefresh();
        searchLayoutHeight = UIUtils.dip2px(44);

        mPresenter.getHomepageInfo();
        mPresenter.getFreedomCreateConfigInfo();

        HomeDetailslBean homeDetailslBean = new Gson().fromJson(SpUtils.getInstance().getString(AppConst.APPBASEINFO), HomeDetailslBean.class);
        if (homeDetailslBean != null && homeDetailslBean.getAppControl() != null) {
            if (homeDetailslBean.getAppControl().getHiddenCustEntrance() == 1) {
                ivPersonalCreate.setVisibility(View.GONE);
            }
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("p0-首页");
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("p0-首页");
    }

    @Override
    public void loadSucceed(String result) {
        refreshLayout.finishRefresh(true);
        if (recyclerView.getVisibility() == View.INVISIBLE) {
            recyclerView.setVisibility(View.VISIBLE);
        }
        if (llSearchLayoutContainer.getVisibility() == View.INVISIBLE) {
            llSearchLayoutContainer.setVisibility(View.VISIBLE);
        }
        V_1_3HomePageDataBean dataBean = new Gson().fromJson(result, V_1_3HomePageDataBean.class);
        setHomePageData(dataBean);
    }

    @Override
    public void loadFaild(String error) {
        refreshLayout.finishRefresh(false);
        T_.showCustomToast("请检查网络");
    }

    private void setHomePageData(V_1_3HomePageDataBean data) {
        if (data == null) return;
        if (data.getBanner() != null && headView != null) {
            initBanner(headView, data.getBanner());
        }
        if (data.getVideoTypes() != null) {
            initClassify(headView);
            classifyAdapter.replaceAll(data.getVideoTypes());
        }
        if (data.getActivitys() != null) {
            initChallengeZone(headView, data.getActivitys());
        }
        if (data.getSpecialTopics() != null) {
            baseRefreshAdapter.setListData(data.getSpecialTopics());
        }

    }

    //初始化刷新
    private void initRefresh() {
        refreshLayout.setDisableContentWhenRefresh(true);
        refreshLayout.setEnableRefresh(true);
        refreshLayout.setEnableLoadMore(false);
        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                mPresenter.getHomepageInfo();
            }
        });
        refreshLayout.setOnMultiPurposeListener(new OnMultiPurposeListener() {
            @Override
            public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) {
                if (offset == 0) {
                    llSearchLayoutContainer.setVisibility(View.VISIBLE);
                } else {
                    if (llSearchLayoutContainer.getVisibility() == View.GONE) return;
                    //15dp 最小触发条件
                    if (offset > UIUtils.dip2px(15))
                        llSearchLayoutContainer.setVisibility(View.GONE);
                }
            }

            @Override
            public void onHeaderReleased(RefreshHeader header, int headerHeight, int maxDragHeight) {

            }

            @Override
            public void onHeaderStartAnimator(RefreshHeader header, int headerHeight, int maxDragHeight) {

            }

            @Override
            public void onHeaderFinish(RefreshHeader header, boolean success) {

            }

            @Override
            public void onFooterMoving(RefreshFooter footer, boolean isDragging, float percent, int offset, int footerHeight, int maxDragHeight) {

            }

            @Override
            public void onFooterReleased(RefreshFooter footer, int footerHeight, int maxDragHeight) {

            }

            @Override
            public void onFooterStartAnimator(RefreshFooter footer, int footerHeight, int maxDragHeight) {

            }

            @Override
            public void onFooterFinish(RefreshFooter footer, boolean success) {

            }

            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {

            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {

            }

            @Override
            public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {

            }
        });

        recyclerView.setHasFixedSize(true);
        layoutManager = new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(baseRefreshAdapter);
        baseRefreshAdapter.setHeaderView(headView, recyclerView);
        baseRefreshAdapter.setCustomLoadMoreView(new GoToMovieFooterView(getContext()));
        recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                int scrollY = getScrollYDistance();
                if (llSearchLayoutContainer.getVisibility() == View.GONE) {
                    llSearchLayoutContainer.setVisibility(View.VISIBLE);
                }
                if (scrollY < searchLayoutHeight) {
                    float percentage = Float.parseFloat(scrollY + "") / searchLayoutHeight;
                    llSearchLayoutContainer.setBackgroundColor(Color.argb((int) (percentage * 255), 20, 20, 20));
                    vStatusBar.setBackgroundColor(Color.argb((int) (percentage * 255), 20, 20, 20));
                } else {
                    llSearchLayoutContainer.setBackgroundColor(Color.argb(255, 20, 20, 20));
                    vStatusBar.setBackgroundColor(Color.argb(255, 20, 20, 20));
                }
            }
        });
    }

    //获取recycleView的滑动距离
    public int getScrollYDistance() {
        LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
        int position = layoutManager.findFirstVisibleItemPosition();
        View firstVisiableChildView = layoutManager.findViewByPosition(position);
        int itemHeight = firstVisiableChildView.getHeight();
        return (position) * itemHeight - firstVisiableChildView.getTop();
    }

    //初始设置statusBar
    private void initStatusBar(View vStatusBar) {
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) vStatusBar.getLayoutParams();
        params.height = StatusBarUtils.getStatusBarHeight(getActivity());
        vStatusBar.setLayoutParams(params);
        vStatusBar.setBackgroundColor(getResources().getColor(R.color.transparent));
    }

    //初始广告轮播
    private void initBanner(View view, AppBanner appBanner) {
        vBanner = view.findViewById(R.id.v_banner);
        List<AppBanner.BannersBean> banners = appBanner.getBanners();
        List<String> bannerImag = new ArrayList<>();
        for (int position = 0; position < banners.size(); position++) {
            bannerImag.add(banners.get(position).getImage());
            oldBannerImages.add(banners.get(position).getImage());
        }
        int width = UIUtils.WHD()[0];
        int height = width * appBanner.getH() / appBanner.getW();
        vBanner.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height));
        //开始轮播
        vBanner.setDelayTime(3000);
        vBanner.setImages(bannerImag).setImageLoader(new GlideImageLoader());
        vBanner.start();
        vBanner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int position) {
                String url = banners.get(position).getUrl();
                if (url.startsWith("http")) {
                    Bundle bundle = new Bundle();
                    bundle.putString(AppConst.WEBTYPE, AppConst.TYPE_WEB);
                    bundle.putString(AppConst.WEBURL, url);
                    openActivity(AdWebActivity.class, bundle);
                }
            }
        });
    }

    //初始化挑战专区
    private void initChallengeZone(View view, ChallengeActionBean bean) {
        CycleGalleryViewPager viewPager = view.findViewById(R.id.view_challenge_zone);
        TextView tv_see_more = view.findViewById(R.id.tv_see_more);
        LinearLayout layout = view.findViewById(R.id.ll_challenge_layout);
        tv_see_more.setVisibility(bean.getShowMore() == 1 ? View.VISIBLE : View.GONE);
        //基础信息控制 是否显示活动 1不显示
        HomeDetailslBean basicInfo = new Gson().fromJson(SpUtils.getInstance().getString(AppConst.APPBASEINFO), HomeDetailslBean.class);
        if (basicInfo != null && basicInfo.getAppControl().getHiddenHomeActivityCarousel() == 1) {
            layout.setVisibility(View.GONE);
            return;
        }
        if (bean == null || bean.getList() == null) return;

        //设置viewPager的宽高属性
        LinearLayout.LayoutParams galleryPagerParams = (LinearLayout.LayoutParams) viewPager.getLayoutParams();
        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        //viewpager中图片的宽
        double nowImageWidth = dm.widthPixels * 0.9;
        double scale = bean.getW() / bean.getH();
        final double nowImageHeight = nowImageWidth / scale;
        //求得图片的宽高
        //加上cardView 10dp的阴影效果
        double nowViewPagerHeight = nowImageHeight + UIUtils.dp2px(10);
        galleryPagerParams.height = (int) nowViewPagerHeight;
        viewPager.setLayoutParams(galleryPagerParams);

        tv_see_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //查看更多
                ((MainActivityV3) getActivity()).setCurrentPageIsChallenge();
            }
        });

        PagerAdapter pagerAdapter = new PagerAdapter() {
            @Override
            public int getCount() {
                return bean.getList().size();
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }

            @Override
            public Object instantiateItem(ViewGroup container, final int position) {
                View view = LayoutInflater.from(getContext()).inflate(R.layout.view_challenge_item, container, false);

                //计算CardView高度
                CardView cardView = view.findViewById(R.id.v_card_view);
                TextView tv_amount = view.findViewById(R.id.tv_amount);
                tv_amount.setText("总奖金:" + (bean.getList().get(position).getRewardTotal() / 100) + "元");
                ImageView ivMoneyTextBr = view.findViewById(R.id.iv_money_br);
                LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) cardView.getLayoutParams();
                params.height = (int) (nowImageHeight);
                cardView.setLayoutParams(params);

                //获取文字宽度 设置底部图片宽度
                Rect bounds = new Rect();
                TextPaint paint;
                paint = tv_amount.getPaint();
                paint.getTextBounds(tv_amount.getText().toString(), 0, tv_amount.getText().toString().length(), bounds);
                int width = bounds.width();
                RelativeLayout.LayoutParams imageParams = (RelativeLayout.LayoutParams) ivMoneyTextBr.getLayoutParams();
                imageParams.width = width + UIUtils.dip2px(16);
                ivMoneyTextBr.setLayoutParams(imageParams);


                ImageLoader.getInstance().showImage(getContext(), bean.getList().get(position).getThumb(), view.findViewById(R.id.iv_image));
                container.addView(view);
                view.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (position != viewPager.getCurrentItem()) {
                            if (position == 0 && viewPager.getCurrentItem() == getCount() - 1) {
                                viewPager.setNextItem();
                            } else if (position == getCount() - 1 && viewPager.getCurrentItem() == 0) {
                                viewPager.setPrivItem();
                            } else {
                                viewPager.setCurrentItem(position);
                            }
                            return;
                        }

                        if (System.currentTimeMillis() - lastClickTime < FAST_CLICK_DELAY_TIME) {
                            return;
                        }
                        lastClickTime = System.currentTimeMillis();

                        //点击跳转到详情
                        ChallengeActionBean.ListBean data = bean.getList().get(position);
                        Bundle bundle = new Bundle();
                        bundle.putString(AppConst.WEBTYPE, AppConst.TYPE_WEB);
                        bundle.putString(AppConst.WEBURL, data.getContentUrl());
                        Intent intent = new Intent(getActivity(), CommWebActivity.class);
                        intent.putExtras(bundle);
                        getActivity().startActivity(intent);
                    }
                });
                return view;
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                container.removeView((View) object);
            }

            @Override
            public float getPageWidth(int position) {
                return 0.9f;
                //建议值为0.6~1.0之间
            }
        };
        viewPager.setAdapter(pagerAdapter);
        viewPager.setCurrentItem(0);
        viewPager.setNarrowFactor(0.96f);
        viewPager.requestDisallowInterceptTouchEvent(false);
    }

    //初始化分类
    private void initClassify(View view) {
        NoScrollGridView gridView = view.findViewById(R.id.gv_classify);
        classifyAdapter = new HomeClassifyAdapter(getContext());
        gridView.setAdapter(classifyAdapter);
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (System.currentTimeMillis() - lastClickTime < FAST_CLICK_DELAY_TIME) {
                    return;
                }
                lastClickTime = System.currentTimeMillis();
//                if (i!=HomeClassifyAdapter.maxItemCount-1){
                //正常
                HomeClassifyBean classifyBean = classifyAdapter.getItem(i);
                HashMap<String, String> map = new HashMap<>();
                map.put("setIds", new Gson().toJson(classifyBean.getSetIds()));
                MobclickAgent.onEvent(getContext(), "c1_home_type_click", map);
                startActivity(ClassifyListActivity.getLaunchIntent(getContext(), classifyBean.getName(), classifyBean.getSetIds(), classifyBean.getShowCondition() == 1));

//                }else {
//                    //更多
//                    HomeClassifyBean classifyBean=classifyAdapter.getItem(i);
//                    startActivity(ClassifyListActivity.getLaunchIntent(getContext(),classifyBean.getName(),classifyBean.getSetIds(),classifyBean.getShowCondition()==1));
//
//                }
            }
        });

    }

    //跳转到搜索
    private void gotoSearch() {
        if (NetUtils.isConnected(getActivity())) {
            //跳转到搜索界面
            Intent intent = new Intent(getActivity(), SearchActivity.class);
            getActivity().startActivity(intent);
        } else {
            T_.showToastReal("请检查网络");
        }
    }

    @Override
    public void onNetWorkStatusChange(boolean b) {
//        Log.e("onNetWorkStatusChange",String.valueOf(b));
//        if (b){
//            refreshLayout.autoRefresh();
//        }
    }

    @Override
    public void onNewWorkEnvironment(NetWorkObservable.NetStateChangeEvent.NetState netState) {
    }

    @Override
    public void getConfigSuccess(String configBean) {
        //获取配置信息成功
        PreferencesHelper.saveData(AppConst.KEY_PERSONAL_CREATE_CONFIG, configBean);
    }

    @Override
    public void getConfigFail(String fail) {
        Log.e("error", "获取自由创建配置信息失败");
    }

    //重置图片宽高
    private List<DesignListBean.ListBean> resetImageWithAndHeight(List<DesignListBean.ListBean> datas, double num, int space) {
        for (DesignListBean.ListBean data : datas) {
            int width = (int) (UIUtils.WHD()[0] / num - UIUtils.dp2px(space));
            int height = width * data.getH() / data.getW();
            String imUrl;
            if (data.getThumb() != null) {
                if (!data.getThumb().contains("?x-oss-process")) {
                    imUrl = ImageLoader.getShrinkImageUrl(data.getThumb(), width, height);
                    data.setThumb(imUrl);
                }
            }
            data.setW(width);
            data.setH(height);
        }
        return datas;
    }

    //homepage页面的适配器
    public class HomepageItemAdapter extends BaseRefreshAdapter<SpecialTopicBean> {

        public HomepageItemAdapter(Context context, List<SpecialTopicBean> datas) {
            super(context, datas, R.layout.item_home_classify_introduce);
        }

        @Override
        protected void convert(BaseRecyclerHolder viewHolder, SpecialTopicBean topicBean, int position) {
            RecyclerView recyclerView = viewHolder.getView(R.id.recycle_videos);
            TextView tv_see_more = viewHolder.getView(R.id.tv_see_more);
            TextView tv_title = viewHolder.getView(R.id.tv_title);
            tv_title.setText(topicBean.getName());
            tv_see_more.setVisibility(topicBean.getShowMore() ? View.VISIBLE : View.GONE);

            recyclerView.setHasFixedSize(true);
            if (topicBean.getDirection() == 1) {
                //横向排布
                RecycleHorizontalItemAdapter horizontalItemAdapter = new RecycleHorizontalItemAdapter(getContext(), null, R.layout.item_main_frag_v_1_3);
                LinearLayoutManager ms = new LinearLayoutManager(getContext());
                ms.setOrientation(LinearLayoutManager.HORIZONTAL);
                recyclerView.setLayoutManager(ms);
                recyclerView.requestDisallowInterceptTouchEvent(false);
                horizontalItemAdapter.setListData(resetImageWithAndHeight(topicBean.getList(), topicBean.getColumn(), (int) Math.round(topicBean.getColumn()) * 5));
                recyclerView.setAdapter(horizontalItemAdapter);
                horizontalItemAdapter.setOnItemClickListener(itemListener);
            } else if (topicBean.getDirection() == 0) {
                //纵向排布
                RecycleVerticalAdapter verticalAdapter = new RecycleVerticalAdapter(getContext(), null, R.layout.itme_main_frag);
                StaggeredGridLayoutManager recyclerViewLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
                recyclerView.setLayoutManager(recyclerViewLayoutManager);
                verticalAdapter.setListData(resetImageWithAndHeight(topicBean.getList(), topicBean.getColumn(), ((int) topicBean.getColumn()) * 5));
                recyclerView.setAdapter(verticalAdapter);
                verticalAdapter.setOnItemClickListener(itemListener);
            }

            //设置点击更多监听
            tv_see_more.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    startActivity(ClassifyListActivity.getLaunchIntent(getActivity(), topicBean.getName(), topicBean.getSetIds(), topicBean.getShowCondition() == 1));
                }
            });
        }
    }

    //教育专区|精品推荐中 item横向RecycleView的适配器
    public class RecycleHorizontalItemAdapter extends BaseRefreshAdapter<DesignListBean.ListBean> {

        public RecycleHorizontalItemAdapter(Context context, List<DesignListBean.ListBean> datas, int itemLayoutId) {
            super(context, datas, itemLayoutId);
        }

        @Override
        protected void convert(BaseRecyclerHolder viewHolder, DesignListBean.ListBean listBean, int position) {
            if (listBean == null) return;
            ImageView imageView = viewHolder.getView(R.id.id_ig);
            TextView tvName = viewHolder.getView(R.id.id_tv_name);
            TextView tvCount = viewHolder.getView(R.id.id_tv_count);
            RelativeLayout llImageLayout = viewHolder.getView(R.id.ll_image_layout);
            ImageView vip_logo = viewHolder.getView(R.id.iv_vip_template);
            vip_logo.setVisibility(listBean.isVipTemplate() ? View.VISIBLE : View.GONE);

            if (position == getListData().size() - 1) {
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(listBean.getW(), ViewGroup.LayoutParams.WRAP_CONTENT);
                params.setMargins(DisplayUtils.dip2px(getContext(), 10), 0, DisplayUtils.dip2px(getContext(), 10), 0);
                llImageLayout.setLayoutParams(params);
            } else {
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(listBean.getW(), ViewGroup.LayoutParams.WRAP_CONTENT);
                params.setMargins(DisplayUtils.dip2px(getContext(), 10), 0, 0, 0);
                llImageLayout.setLayoutParams(params);
            }

            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) imageView.getLayoutParams();
            layoutParams.width = listBean.getW();
            layoutParams.height = listBean.getH();
            ImageLoader.getInstance().showCircleImageWithBorder(getContext(), listBean.getThumb(), imageView);
            tvName.setText(listBean.getName());
            LinearLayout.LayoutParams textParams = (LinearLayout.LayoutParams) tvName.getLayoutParams();
            textParams.width = listBean.getW();
            tvName.setLayoutParams(textParams);
            tvName.setEllipsize(TextUtils.TruncateAt.END);
            tvName.setSingleLine(true);
            tvCount.setText(listBean.getUseCounts() + "人使用");
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onItemClickListener != null) {
                        onItemClickListener.onItemSelect(listBean);
                    }
                }
            });
        }
    }

    //教育专区|精品推荐中 item竖向RecycleView的适配器
    public class RecycleVerticalAdapter extends BaseRefreshAdapter<DesignListBean.ListBean> {

        private List<DesignListBean.ListBean> mData;

        public RecycleVerticalAdapter(Context context, List<DesignListBean.ListBean> datas, int itemLayoutId) {
            super(context, datas, itemLayoutId);
            mData = datas;
        }

        @Override
        protected void convert(BaseRecyclerHolder viewHolder, DesignListBean.ListBean listBean, int position) {
            if (listBean == null) return;
            ImageView imageView = viewHolder.getView(R.id.id_ig);
            TextView tvName = viewHolder.getView(R.id.id_tv_name);
            TextView tvCount = viewHolder.getView(R.id.id_tv_count);
            ImageView vip_logo = viewHolder.getView(R.id.iv_vip_template);
            vip_logo.setVisibility(listBean.isVipTemplate() ? View.VISIBLE : View.GONE);
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) imageView.getLayoutParams();
            layoutParams.width = listBean.getW();
            layoutParams.height = listBean.getH();
            ImageLoader.getInstance().showCircleImageWithBorder(getContext(), listBean.getThumb(), imageView);
            tvName.setText(listBean.getName());
            LinearLayout.LayoutParams textParams = (LinearLayout.LayoutParams) tvName.getLayoutParams();
            textParams.width = listBean.getW();
            tvName.setLayoutParams(textParams);
            tvName.setEllipsize(TextUtils.TruncateAt.END);
            tvName.setSingleLine(true);
            tvCount.setText(listBean.getUseCounts() + "人使用");
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onItemClickListener != null) {
                        onItemClickListener.onItemSelect(listBean);
                    }
                }
            });
        }
    }
}
